package com.huiminpay.transaction.mq;


import com.huiminpay.transaction.dto.PayOrderMqDto;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

/**
 * 发送延迟消息
 */
@Component
@Slf4j
public class PayProducer {


    @Autowired
    RocketMQTemplate rocketMQTemplate;

    public void sendMsByDelay(String topic, PayOrderMqDto payOrderMqDto){

        //封装类消息体
        Message<PayOrderMqDto> message = MessageBuilder.withPayload(payOrderMqDto).build();

        /**
         * topic 主题
         * message 消息
         * timeout 超时时间
         * 延迟时间等级
         */
        rocketMQTemplate.syncSend(topic,message,1000,3);
        log.info("消息发送{}",topic +":  "+message);

    }
}
